import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

import org.korifey.ffalg.FFBitSet;
import org.korifey.ffalg.NumberTheory;
import org.korifey.ffalg.Probabilities;


public class Problem24 {
	
	public static void main(String[] args) {
		System.out.println(solve());
	}
	static int n = 1000000;		
	static int ndigits = 10;
	private static int[] fact = new int[ndigits];
	static {
		fact[0] = 1;
		for (int i=1; i<fact.length; i++) fact[i] = fact[i-1]*i;
	}
		
	static boolean[] digs = new boolean[ndigits];
	static int takeDigit(int x) {
		for (int i=0, idx=-1; ; i++) {
			if (!digs[i]) {
				idx++;
				if (idx == x) {
					digs[i] = true;
					return i; 
				}
			}
		}		
	}
	
	public static String solve() {
		n -= 1;
		
		StringBuilder res = new StringBuilder(ndigits);
		for (int radix = ndigits-1; radix >= 0; radix--) {
			res.append(takeDigit(n / fact[radix]));
			n %= fact[radix];
		}
		return res.toString();
	}
	
}
